package com.ttc.group2.videochat.utils;

import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.view.View;
import android.widget.Toast;

import com.ttc.group2.videochat.R;

public class DialogUtils {

	private static Toast toast;

	public static void showToast(Context context, String message, int duration) {
		if (message == null) {
			return;
		}
		if (toast == null && context != null) {
			toast = Toast.makeText(context, message, duration);
		}
		if (toast != null) {
			toast.setText(message);
			toast.show();
		}
	}

	public static Dialog createDialog(Context context, int titleId,
			int messageId,
			DialogInterface.OnClickListener positiveButtonListener,
			DialogInterface.OnClickListener negativeButtonListener) {

		AlertDialog.Builder builder = new AlertDialog.Builder(context);
		builder.setTitle(titleId);
		builder.setMessage(messageId);
		builder.setPositiveButton(R.string.dlg_ok, positiveButtonListener);
		builder.setNegativeButton(R.string.dlg_cancel, negativeButtonListener);

		return builder.create();
	}

	public static Dialog createDialog(Context context, int titleId,
			int messageId, View view,
			DialogInterface.OnClickListener positiveClickListener,
			DialogInterface.OnClickListener negativeClickListener) {

		AlertDialog.Builder builder = new AlertDialog.Builder(context);
		builder.setTitle(titleId);
		builder.setMessage(messageId);
		builder.setView(view);
		builder.setPositiveButton(R.string.dlg_ok, positiveClickListener);
		builder.setNegativeButton(R.string.dlg_cancel, negativeClickListener);

		return builder.create();
	}

	public static ProgressDialog getProgressDialog(Context context) {
		ProgressDialog progressDialog = new ProgressDialog(context);
		progressDialog.setCancelable(false);
		progressDialog.setMax(100);
		progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
		progressDialog.setMessage(context.getResources().getString(
				R.string.please_wait));
		return progressDialog;
	}
}
